package jianzhi

func singleNumber2_1(nums []int) int {
	count := make(map[int]int)

	for _, v := range nums {
		if _, ok := count[v]; ok {
			count[v]++
		} else {
			count[v] = 1
		}
	}

	for k, v := range count {
		if v == 1 {
			return k
		}
	}

	return -1
}

func singleNumber(nums []int) int {
	res := 0
	for i := 0; i < 32; i++ {
		count := 0
		bit := 1 << i
		for _, num := range nums {
			if num&bit != 0 {
				count++
			}
		}
		if count%3 != 0 {
			res |= bit
		}
	}
	return res
}
